﻿using System;
using System.Collections.Generic;
using System.Text;
using ALMDDD.Domain.Core.Events;
using ALMDDD.Infrastructure.Context;
using System.Linq;
namespace ALMDDD.Infrastructure.Repository.EventSourcing
{
    public class EventStoreRepository : IEventStoreRepository
    {

        private readonly EventStoreSQLContext _context;
        private EventStoreRepository(EventStoreSQLContext eventStoreSQLContext)
        {
            _context = eventStoreSQLContext;
        }
        public IList<StoredEvent> All(Guid aggregateId)
        {

            return (from e in _context.StoredEvent where e.AggregateId == aggregateId select e).ToList();
        }

        public void Store(StoredEvent storedEvent)
        {
            _context.StoredEvent.Add(storedEvent);
            _context.SaveChanges();
        }

        /// <summary>
        /// 手动回收
        /// </summary>
        public void Dispose()
        {
            _context.Dispose();
        }
    }
}
